import React, { Component } from 'react'
import AddCounter from './AddCounter'

// 子组件向父组件(App)通信
// 父组件定义的函数通过可以像父向子传值的写法把该函数传递到子组件，子组件可以通过props调用父组件的函数通过调用传参把数据传给父组件，父组件在该函数中通过形参取到
class App extends Component {
  constructor() {
    super()
    this.state = {
      count : 100
    }
  }
  addClick(count) {
    console.log('父组件定义的函数',count);
    this.setState({
      count: this.state.count + count
    })
  }
  render() {
    const {count } = this.state
    return (
      <div>
        <h2>当前计数为：{ count}</h2>
        <AddCounter addClick={ (count) => this.addClick(count)} />
      </div>
    )
  }
}

export default App